const Koa = require('koa');
const bodyparser = require('koa-bodyparser');
const registryRouter = require('../router');
const errorMiddleware = require('../middleware/error');
const registerExtensions = require('../extension');

const { registerPreGloablMiddlewares } = require('../middleware');
const app = new Koa();
app.registryRouter = registryRouter;
app.registerPreGloablMiddlewares = registerPreGloablMiddlewares;
app.registerExtensions = registerExtensions;

app.use(bodyparser());
app.registerExtensions();
app.registerPreGloablMiddlewares();
app.registryRouter();

app.on('error', errorMiddleware);

module.exports = app;
